package com.hwz.gulimall.ware.service.impl;

import com.hwz.common.to.SkuHasStockTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwz.common.utils.PageUtils;
import com.hwz.common.utils.Query;

import com.hwz.gulimall.ware.dao.WareSkuDao;
import com.hwz.gulimall.ware.entity.WareSkuEntity;
import com.hwz.gulimall.ware.service.WareSkuService;
import org.springframework.util.StringUtils;


@Service("wareSkuService")
public class WareSkuServiceImpl extends ServiceImpl<WareSkuDao, WareSkuEntity> implements WareSkuService {

    @Autowired
    WareSkuDao wareSkuDao;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<WareSkuEntity> wareSkuEntityQueryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(params.get("skuId"))){
            wareSkuEntityQueryWrapper.eq("sku_id", params.get("skuId"));
        }

        if (!StringUtils.isEmpty(params.get("wareId"))){
            wareSkuEntityQueryWrapper.eq("ware_id", params.get("wareId"));
        }

        IPage<WareSkuEntity> page = this.page(
                new Query<WareSkuEntity>().getPage(params),
                wareSkuEntityQueryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<SkuHasStockTo> hasStock(List<Long> skuIds) {
        List<SkuHasStockTo> skuHasStockTos = this.baseMapper.hasStock(skuIds);
        return skuHasStockTos;


    }

}